package com.zhj.interview;

/**
 * @author zhj
 */
public class Test30 {

    private static volatile int state = 0;

    public static void main(String[] args) {
        Thread threadA = new Thread(new printA());
        Thread threadB = new Thread(new printB());
        Thread threadC = new Thread(new printC());
        threadA.start();
        threadB.start();
        threadC.start();
    }

    static class printA implements Runnable {

        public void run() {
            for (int i = 0; i < 10; ) {
                //synchronized (Test30.class) {
                    while (state % 3 == 0) {
                        System.out.println("A");
                        state++;
                        i++;
                    }
                //}
            }
        }
    }

    static class printB implements Runnable {

        public void run() {
            for (int i = 0; i < 10;) {
                //synchronized (Test30.class) {
                    while (state % 3 == 1) {
                        System.out.println("B");
                        state++;
                        i++;
                    }
                //}
            }
        }
    }

    static class printC implements Runnable {

        public void run() {
            for (int i = 0; i < 10;) {
                //synchronized (Test30.class) {
                    while (state % 3 == 2) {
                        System.out.println("C");
                        state++;
                        i++;
                    }
                //}
            }
        }
    }


}
